<template>
    <div id="OrdersTitle">
        <v-details :inputConfig="inputConfig" :detailData="inputData" :rules="rules" @pop="setdata"
                   ref="input"></v-details>
    </div>
</template>

<script>
    import details from 'commons/Detail'
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        props: {
            inputData: {
                type: Object,
            }
        },
        mixins: [baseMixin],
        name: "OrdersTitle",
        data() {
            return {
                addflag: false,
                flag1: true,
                flag2: true,
                rules: {
                    charge_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    charge_desc: [
                        {required: true, trigger: 'blur'},
                    ],
                    charge_code_type: [
                        {required: true, trigger: 'blur'},
                    ],
                    charge_group: [
                        {required: true, trigger: 'blur'},
                    ],
                    def_cr_corp: [
                        {required: true, trigger: 'blur'},
                    ],
                    def_cr_dept: [
                        {required: true, trigger: 'blur'},
                    ],
                    def_cr_acct: [
                        {required: true, trigger: 'blur'},
                    ],
                },
            }
        },
        computed: {
            inputConfig() {
                return [
                    [
                        {
                            type: "input",
                            label: this.$t('bill.chargeCode'),
                            props: "charge_code",
                            disabled: this.addflag
                        },
                        {
                            type: "input",
                            label: this.$t('bill.desc'),
                            props: "charge_desc",
                        },
                        {
                            type: "select",
                            label: this.$t('bill.chargeType'),
                            props: "charge_code_type",
                            options: this.getOptions("queryChargeType/zh")
                        },
                        {
                            type: "select",
                            label: this.$t('bill.chargeGroup'),
                            props: "charge_group",
                            options: this.getOptions("queryChargeGroup")
                        },
                    ],
                    [
                        {
                            type: "table",
                            label: this.$t('bill.defaultCorp'),
                            props: "def_cr_corp",
                            tableConfig: [
                                {
                                    label: this.$t('bill.corpCode'),
                                    prop: "corp_code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('bill.desc'),
                                    prop: "corp_name",
                                    input: "input",
                                }
                            ],
                            url: `/queryCorporation/?/${this.$store.state.wms}`
                        },
                        {
                            type: "table",
                            label: this.$t('bill.defaultDepart'),
                            props: "def_cr_dept",
                            tableConfig: [
                                {
                                    label: this.$t('bill.departCode'),
                                    prop: "dept_code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('bill.desc'),
                                    prop: "dept_name",
                                    input: "input",
                                }
                            ],
                            url: `/queryDepartment/${this.inputData.def_cr_corp}/?/${this.$store.state.wms}`,
                            disabled: this.flag1
                        },
                        {
                            type: "table",
                            label: this.$t('bill.defaultAccount'),
                            props: "def_cr_acct",
                            tableConfig: [
                                {
                                    label: this.$t('bill.accountCode'),
                                    prop: "acct_code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('bill.desc'),
                                    prop: "acct_name",
                                    input: "input",
                                }
                            ],
                            url: `/queryAccount/${this.inputData.def_cr_corp}/${this.inputData.def_cr_dept}/?/${this.$store.state.wms}`,
                            disabled: this.flag2
                        },
                    ]
                ]
            },
        },
        methods: {
            setdata(data, id, close, listId) {
                if (listId == "1" && id == "0") {
                    this.inputData.def_cr_corp = data.corp_code;
                } else if (listId == "1" && id == "1") {
                    this.inputData.def_cr_dept = data.dept_code;
                } else if (listId == "1" && id == "2") {
                    this.inputData.def_cr_acct = data.acct_code;
                }
                close(false);
            }
        },
        mounted() {
            if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                if (!data.newFlag) {
                    this.addflag = true;
                }
            } else if (!this.$store.state.newFlag) {
                this.addflag = true;
            }
        },
        watch: {
            "inputData.def_cr_corp"(data) {
                if (data != "") {
                    this.flag1 = false;
                } else {
                    this.flag1 = true
                }
            },
            "inputData.def_cr_dept"(data) {
                if (data != "") {
                    this.flag2 = false;
                } else {
                    this.flag2 = true
                }
            }
        },
        components: {
            'v-details': details
        }
    }
</script>

<style scoped>

</style>
